package com.cicadamob.contact.api.service;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.AsyncTask;
import android.provider.BaseColumns;
import android.util.Log;

import com.cicadamob.contact.api.Utils.StringUtil;
import com.cicadamob.contact.api.Utils.Data.SharedPreferencesUtil;

/**
 * 
 * 
 * @author mzz
 * 
 */
public class AppDbHelper extends SQLiteOpenHelper {

	private final static String DB_NAME = "app_db.db";
	private final static String TABLE_NAME = "sms_table";
	private final static String TABLE_INSTALL = "install_table";
	// public final static int SQL_VERSION = 24;
	/** 群组表 **/
	public final static String TABLE_GROUP = "TS_GROUP_NAME";
	/** 群组成员表 **/
	public final static String TABLE_GROUP_USER = "TS_GROUP_USER";

	/** 数据版本信息表 **/
	public final static String TABLE_DATA_VERSION = "dataVersion";
	public final static int VERSION = 8;

	/** 注意：只有在onCreate中使用，在onCreate最后赋值未null **/
	private Context mContext;

	// 调用父类构造器，用于创建数据库
	private AppDbHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
		mContext = context;
	}

	public static AppDbHelper newInstance(Context context) {
		return new AppDbHelper(context);
	}

	@SuppressLint("NewApi")
	@Override
	public void onCreate(SQLiteDatabase db) {

		// 创建应用中心表
		db.execSQL("create table if not exists " + APP_DOWNLOAD_INFO.TABLE_NAME + "("
				+ APP_DOWNLOAD_INFO.APP_ID + " TEXT primary key ," + APP_DOWNLOAD_INFO.URL
				+ " TEXT," + APP_DOWNLOAD_INFO.ICON + " TEXT," + APP_DOWNLOAD_INFO.NAME + " TEXT,"
				+ APP_DOWNLOAD_INFO.FILE_SIZE + " TEXT," + APP_DOWNLOAD_INFO.FILE_PATH + " TEXT,"
				+ APP_DOWNLOAD_INFO.DOWNLOADED_SIZE + " TEXT," + APP_DOWNLOAD_INFO.PACKAGE
				+ " TEXT," + APP_DOWNLOAD_INFO.DETAIL + " TEXT," + APP_DOWNLOAD_INFO.VERISON_CODE
				+ " TEXT," + APP_DOWNLOAD_INFO.VERSION_NAME + " TEXT," + APP_DOWNLOAD_INFO.STATUS
				+ " TEXT," + APP_DOWNLOAD_INFO.REMARK + " TEXT)");

		// 执行时，若表不存在，则创建之，注意SQLite数据库中必须有一个_id的字段作为主键，否则查询时将报错
		db.execSQL("create table if not exists " + TABLE_NAME
				+ "(_id integer primary key autoincrement," + "smstext varchar," + "time varchar,"
				+ "issuccess integer default 1," + "dstname varchar)");

		db.execSQL("create table if not exists common_contact"
				+ "(id integer primary key autoincrement, " + "person_name varchar,"
				+ "person_tel varchar," + "group_name varchar," + "pinyin varchar)");

		db.execSQL("create table if not exists groups_table"
				+ "(id integer primary key autoincrement, " + "person_name varchar, "
				+ "person_tel varchar, " + "group_name varchar)");

		// 此表保存手机系统保存的联系人的安装状态
		db.execSQL("create table if not exists install_table"
				+ "(id integer primary key autoincrement, " + "install_phone varchar,"
				+ " p_name varchar , " + "remark1 varchar, " + "remark2 varchar)");

		// 此表保存已经建立好友关系的联系人（将手机系统的联系人的号码和名称都上传到服务端建立好友关系，用于生成好友动态）
		db.execSQL("create table if not exists " + RelationTable.TABLE_NAME + "("
				+ RelationTable.ID + " integer primary key autoincrement, " + RelationTable.TEL
				+ " varchar," + RelationTable.NAME + " varchar , " + "remark1 varchar, "
				+ "remark2 varchar)");

		// 添加常用人
		db.execSQL("create table if not exists common_person"
				+ "(id integer primary key autoincrement, " + "person_name varchar, "
				+ "person_tel varchar, " + "source_id varchar," + "job varchar,"
				+ "company varchar," + "nick_name varchar,install integer)");

		// 群组表
		/**
		 * comment on column TS_GROUP_NAME.UUID is '群名称信息-主键32位id'; comment on
		 * column TS_GROUP_NAME.GROUP_NAME is '群名称'; comment on column
		 * TS_GROUP_NAME.CREATE_USER is '创建者账号'; comment on column
		 * TS_GROUP_NAME.CREATE_DATE is '创建时间'; comment on column
		 * TS_GROUP_NAME.GROUP_STATUS is '群状态1：可用。2：冻结'; comment on column
		 * TS_GROUP_NAME.GROUP_REMARK is '备注信息'; comment on column
		 * TS_GROUP_NAME.USERNAME is '创建者名称'; comment on column
		 * TS_GROUP_NAME.SPNAME is '群名称首拼音'; comment on column 小写
		 * TS_GROUP_NAME.QPNAME is '群名称全拼'; comment on column 小写
		 * TS_GROUP_NAME.FNAME_FPY_NUM is '群名称拼音的前12个字母的Long排序值';
		 */
		db.execSQL("create table if not exists " + TABLE_GROUP + " (UUID integer primary key ,"
				+ "GROUP_NAME varchar," + "CREATE_USER varchar," + "CREATE_DATE varchar,"
				+ "GROUP_STATUS varchar," + "GROUP_REMARK varchar," + "USERNAME varchar,"
				+ "SPNAME varchar," + "QPNAME varchar," + "FNAME_FPY_NUM integer,"
				+ TS_GROUP_NAME.IMAGEPATH + " varchar," + "assetId varchar,"
				+ "GROUP_STATE integer DEFAULT ((1)))");

		StringBuilder sql = new StringBuilder("create table if not exists "
				+ CALL_LOG_INFO.TABLE_NAME);
		sql.append("( _id integer primary key autoincrement,");
		sql.append("name varchar(20),");
		sql.append("tel varchar(12),");
		sql.append("callStatus varchar(2),");
		sql.append(CALL_LOG_INFO.CALL_TYPE + " varchar,");
		sql.append(CALL_LOG_INFO.OUTSITE_PREFIX + " varchar,");
		sql.append(CALL_LOG_INFO.OTHERPLACE_PREFIX + " varchar,");
		sql.append(CALL_LOG_INFO.DURATON + " integer default -1,");
		sql.append(CALL_LOG_INFO.SOUNDURL + " varchar(100),");
		sql.append(CALL_LOG_INFO.SOUND_TIME + " varchar(10),");
		sql.append(
				"time INTEGER, isUp varchar(2), install integer, " + CALL_LOG_INFO.IS_READ
						+ " varchar(2) ").append(")");
		// 执行sql语句
		db.execSQL(sql.toString());

		// // 添加常用人
		// db.execSQL("create table if not exists common_person"
		// + "(id integer primary key autoincrement, "
		// + "person_name varchar, " + "person_tel varchar, "
		// + "source_id varchar," + "job varchar," + "company varchar,"
		// + "nick_name varchar,install integer)");
		// // 添加常用(同事，个人)
		// db.execSQL("create table if not exists common_team"
		// + "(id integer primary key autoincrement, "
		// + "team_id varchar," + "team_name varchar, "
		// + "teams_hasParent boolean, " + "team_hasChild boolean,"
		// + "team_parent integer," + "team_level integer)");

		db.execSQL("create trigger group_Delete " + " before delete on " + TABLE_GROUP
				+ " for each row " + " begin " + "  delete from " + TABLE_GROUP_USER + " where "
				+ TS_GROUP_USER.GROUP_ID + " =" + " old.UUID" + ";" + "  delete from "
				+ TABLE_DATA_VERSION + " where " + TS_DATA_VERSION.GROUP_ID + " =" + " old.UUID"
				+ ";"
				// +"  delete from common_team where team_id ="+" old.UUID"+";"
				+ " end;");

		// 更新群组的触发器
		/*
		 * db.execSQL("DROP TRIGGER group_Update ");
		 * db.execSQL("create trigger group_Update "
		 * +" before update on "+TABLE_GROUP +" for each row " +" begin "
		 * +"  update common_team " + " set team_name = new.GROUP_NAME" +
		 * " where team_id = old.UUID;" +" end;");
		 */

		// 群组成员表
		/**
		 * comment on column TS_GROUP_USER.GU_UUID is '群成员信息表-主键id'; comment on
		 * column TS_GROUP_USER.GROUP_ID is '群id(唯一值)'; comment on column
		 * TS_GROUP_USER.USERTYPE is '群成员类型1:群主，2：群成员'; comment on column
		 * TS_GROUP_USER.DISPLAYNAME is '显示名称'; comment on column
		 * TS_GROUP_USER.USER_ACCOUNT is '用户账号'; comment on column
		 * TS_GROUP_USER.USER_STATUS is '用户状态0：待审核；1：可用。2：冻结'; comment on column
		 * TS_GROUP_USER.CREATE_DATE is '创建时间'; comment on column
		 * TS_GROUP_USER.CREATE_USER is '创建人账号'; comment on column
		 * TS_GROUP_USER.GU_REMARK is '备注信息'; comment on column
		 * TS_GROUP_USER.ISAUT is '是否已经认证 0：未认证。1： 已经认证'; comment on column
		 * TS_GROUP_USER.SPNAME is '名字首拼音'; comment on column
		 * TS_GROUP_USER.QPNAME is '名称全拼'; comment on column
		 * TS_GROUP_USER.ISJTUSER is '是否是集团用户0：否。1： 是'; comment on column
		 * TS_GROUP_USER.COMPANY is '公司名称'; comment on column
		 * TS_GROUP_USER.DEPARTMENT is '部门名称'; comment on column
		 * TS_GROUP_USER.JOBPROFESSION is '职位'; comment on column
		 * TS_GROUP_USER.FNAME_FPY_NUM is '姓名拼音的前12个字母的Long排序值';
		 * TS_GROUP_USER.INSTALL is '该成员是否安装了客户端' 1 是安装 ，0是没安装;
		 **/
		db.execSQL("create table if not exists " + TABLE_GROUP_USER
				+ " (GU_UUID varchar primary key," + "GROUP_ID varchar," + "USERTYPE varchar,"
				+ "DISPLAYNAME varchar," + "USER_ACCOUNT varchar," + "USER_STATUS varchar,"
				+ "CREATE_DATE varchar," + "CREATE_USER varchar," + "GU_REMARK varchar,"
				+ "ISAUT varchar," + "SPNAME varchar," + "QPNAME varchar," + "ISJTUSER varchar,"
				+ "COMPANY varchar," + "DEPARTMENT varchar," + "JOBPROFESSION varcahr,"
				+ "ISTEMP varcahr," + "FNAME_FPY_NUM integer," + "INSTALL integer)");
		/**
		 * 此表用于保存桌面小部件快捷联系人列表 ID 主键 NAME 联系人名称 PHONE 联系人电话 APPWIDGET_ID
		 * 联系人所属小部件id
		 */
		db.execSQL("create table if not exists " + WidgetContactListTable.TABLE_NAME + " ("
				+ WidgetContactListTable.ID + " integer primary key autoincrement,"
				+ WidgetContactListTable.NAME + " varchar," + WidgetContactListTable.PHONE
				+ " varchar," + WidgetContactListTable.APPWIDGET_ID + " integer)");
		/**
		 * 此表用于保存联系人信息
		 */
		db.execSQL("create table if not exists " + APP_CONTACTS.TABLE_NAME + " (" + APP_CONTACTS.ID
				+ " integer primary key autoincrement," + APP_CONTACTS.DISPLAY_NAME + " varchar,"
				+ APP_CONTACTS.EMAIL_ADDREDD + " varchar," + APP_CONTACTS.IS_COMMON_CONTACT
				+ " integer default 0," + APP_CONTACTS.ALL_CHARACTER + " varchar,"
				+ APP_CONTACTS.ALL_CHARACTER_T9 + " varchar," + APP_CONTACTS.FIRST_CHARACTER
				+ " varchar," + APP_CONTACTS.FIRST_CHARACTER_T9 + " varchar,"
				+ APP_CONTACTS.PHOTO_ID + " varchar)");
		/**
		 * 此表用于保存联系人号码等信息
		 */
		db.execSQL("create table if not exists " + APP_CONTACTS_DATA.TABLE_NAME + " ("
				+ APP_CONTACTS_DATA.ID + " integer primary key autoincrement,"
				+ APP_CONTACTS_DATA.DATA + " varchar," + APP_CONTACTS_DATA.TYPE
				+ " varchar default \"phone\"," + APP_CONTACTS_DATA.CONTACTS_ID
				+ " integer REFERENCES " + APP_CONTACTS.TABLE_NAME + "(" + APP_CONTACTS.ID
				+ ") ON DELETE CASCADE)");
		db.execSQL("create table if not exists " + IMS_ACCOUNT_INFO.TABLE_NAME + " ("
				+ IMS_ACCOUNT_INFO.ACCOUNT_ID + " integer primary key autoincrement, "
				+ IMS_ACCOUNT_INFO.IMS_ACCOUNT + " varchar, " + IMS_ACCOUNT_INFO.IMS_PASSWORD
				+ " varchar, " + IMS_ACCOUNT_INFO.IMS_REALM + " varchar, "
				+ IMS_ACCOUNT_INFO.IMS_HOST + " varchar, " + IMS_ACCOUNT_INFO.IMS_PORT
				+ " varchar, " + IMS_ACCOUNT_INFO.IMS_IMPI + " varchar) ");
		
		/**
		 * 创建企业常用联系人，在数据库版本8之后添加
		 */
		db.execSQL("create table if not exists " + COMPANY_COMMON_CONTACT.TABLE_NAME + " ("
				+ COMPANY_COMMON_CONTACT._ID + " integer primary key autoincrement, "
				+ COMPANY_COMMON_CONTACT.DISPLAY_NAME + " varchar, " + COMPANY_COMMON_CONTACT.PHONE
				+ " varchar, " + COMPANY_COMMON_CONTACT.UUID + " integer) ");
		
		/**
		 * 驱动异步任务 复制系统联系人到本地数据库
		 */
		SyncSysContactAsynTask backupTask = new SyncSysContactAsynTask(mContext);
		backupTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// String update2Create = "Create TABLE MAIN.[Temp_123244231](" +
		// "[_id] integer PRIMARY KEY AUTOINCREMENT," +
		// "[smstext] varchar,[time] varchar," +
		// "[dstname] varchar,[issuccess] integer DEFAULT 1)";
		// String update2Insert =
		// "Insert Into MAIN.[Temp_123244231] ([_id],[smstext],[time],[dstname])"
		// + "Select [_id],[smstext],[time],[dstname] From MAIN.[sms_table]";
		// String update2Drop = "Drop Table MAIN.[sms_table]";
		// String update2Alter =
		// "Alter Table MAIN.[Temp_123244231] Rename To [sms_table]";
		// db.execSQL(update2Create);
		// db.execSQL(update2Insert);
		// db.execSQL(update2Drop);
		// db.execSQL(update2Alter);
		// db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		// db.execSQL("DROP TABLE IF EXISTS " + TABLE_GROUP);

		db.execSQL("DROP TABLE IF EXISTS " + TABLE_INSTALL);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_GROUP_USER);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_DATA_VERSION);
		// db.execSQL("DROP TABLE IF EXISTS common_person");
		// db.execSQL("DROP TABLE IF EXISTS " + CALL_LOG_INFO.TABLE_NAME);
		// 删除群组的触发器
		db.execSQL("DROP TRIGGER group_Delete ");

		onCreate(db);

		if (1 == oldVersion) {
			String sql = "ALTER TABLE " + TABLE_GROUP + " ADD COLUMN assetId varchar";// 群组表添加一个字段（assetId
																						// varchar）
			db.execSQL(sql);
		}

		// if(3==oldVersion){
		// String
		// sql="ALTER TABLE "+CALL_LOG_INFO.TABLE_NAME+" ADD COLUMN "+CALL_LOG_INFO.CALL_TYPE+" TEXT";//通话记录表添加一个字段（callType
		// varchar）
		// db.execSQL(sql);
		// }
		if (4 == oldVersion) {
			String sql = "ALTER TABLE " + CALL_LOG_INFO.TABLE_NAME + " ADD COLUMN "
					+ CALL_LOG_INFO.IS_READ + " varchar(2)";
		}

		if (oldVersion <= 5) {
			Log.i("AppDbHelper", "旧版本IMS账户缓存转存数据库");
			String imsAccount = SharedPreferencesUtil.getString(mContext, "IMS_ACCOUNT");
			String imsPassword = SharedPreferencesUtil.getString(mContext, "IMS_PASSWORD");
			String imsReaml = SharedPreferencesUtil.getString(mContext, "IMS_YUMING");
			String imsHost = SharedPreferencesUtil.getString(mContext, "IMS_HOST");
			int imsPort = SharedPreferencesUtil.getInt(mContext, "IMS_PORT");
			String imsImpi = SharedPreferencesUtil.getString(mContext, "IMS_IMPI");
			Log.i("AppDbHelper", "imsAccount=" + imsAccount + ",imsPassword=" + imsPassword
					+ ",imsReaml=" + imsReaml + ",imsHost=" + imsHost + ",imsPort=" + imsPort
					+ ",imsImpi=" + imsImpi);
			if (StringUtil.isNotNullOrEmpty(imsAccount) && StringUtil.isNotNullOrEmpty(imsPassword)
					&& StringUtil.isNotNullOrEmpty(imsReaml)
					&& StringUtil.isNotNullOrEmpty(imsHost)) {
				String insertSql = "INSERT INTO " + IMS_ACCOUNT_INFO.TABLE_NAME + " ("
						+ IMS_ACCOUNT_INFO.IMS_ACCOUNT + ", " + IMS_ACCOUNT_INFO.IMS_PASSWORD
						+ ", " + IMS_ACCOUNT_INFO.IMS_REALM + ", " + IMS_ACCOUNT_INFO.IMS_HOST
						+ ", " + IMS_ACCOUNT_INFO.IMS_PORT + ", " + IMS_ACCOUNT_INFO.IMS_IMPI
						+ ") values ('" + imsAccount + "', '" + imsPassword + "', '" + imsReaml
						+ "', '" + imsHost + "', '" + imsPort + "', '" + imsImpi + "')";
				Log.i("AppDbHelper", "insertSql>>>" + insertSql);
				db.execSQL(insertSql);
			}
		}

		if (5 == oldVersion) {
			// 通话记录表添加一个字段outsite_Prefix - 外线字冠
			db.execSQL("ALTER TABLE " + CALL_LOG_INFO.TABLE_NAME + " ADD COLUMN "
					+ CALL_LOG_INFO.OUTSITE_PREFIX + " varchar");
			// 通话记录表添加一个字段otherPlacePrefix - 外地字冠
			db.execSQL("ALTER TABLE " + CALL_LOG_INFO.TABLE_NAME + " ADD COLUMN "
					+ CALL_LOG_INFO.OTHERPLACE_PREFIX + " varchar");
			// 通话记录表添加一个字段 DURATON - 时长
			db.execSQL("ALTER TABLE " + CALL_LOG_INFO.TABLE_NAME + " ADD COLUMN "
					+ CALL_LOG_INFO.DURATON + " integer default -1");
		}

		if (6 == oldVersion) {
			// 联系人信息表添加一个字段 is_common_contact 是否为常用联系人
			db.execSQL("ALTER TABLE " + APP_CONTACTS.TABLE_NAME + " ADD COLUMN "
					+ APP_CONTACTS.IS_COMMON_CONTACT + " integer default 0");
		}

	}

	/*
	 * comment on column TS_GROUP_NAME.UUID is '群名称信息-主键32位id';
	 * 
	 * comment on column TS_GROUP_NAME.GROUP_NAME is '群名称';
	 * 
	 * comment on column TS_GROUP_NAME.CREATE_USER is '创建者账号';
	 * 
	 * comment on column TS_GROUP_NAME.CREATE_DATE is '创建时间';
	 * 
	 * comment on column TS_GROUP_NAME.GROUP_STATUS is '群状态1：可用。2：冻结';
	 * 
	 * comment on column TS_GROUP_NAME.GROUP_REMARK is '备注信息';
	 * 
	 * comment on column TS_GROUP_NAME.USERNAME is '创建者名称';
	 * 
	 * comment on column TS_GROUP_NAME.SPNAME is '群名称首拼音';
	 * 
	 * comment on column TS_GROUP_NAME.QPNAME is '群名称全拼'; comment on column
	 * TS_GROUP_NAME.FNAME_FPY_NUM is '群名称拼音的前12个字母的Long排序值'; IMAGEPATH 图片路径
	 */

	public static final class TS_GROUP_NAME implements BaseColumns {
		private TS_GROUP_NAME() {

		}

		public static final String UUID = "UUID";
		public static final String GROUP_NAME = "GROUP_NAME";
		public static final String CREATE_USER = "CREATE_USER";
		public static final String CREATE_DATE = "CREATE_DATE";
		public static final String GROUP_STATUS = "GROUP_STATUS";
		public static final String GROUP_REMARK = "GROUP_REMARK";
		public static final String USERNAME = "USERNAME";
		public static final String SPNAME = "SPNAME";
		public static final String QPNAME = "QPNAME";
		public static final String FNAME_FPY_NUM = "FNAME_FPY_NUM";
		public static final String STATE = "GROUP_STATE";
		public static final String IMAGEPATH = "image_path";
		public static final String ASSETID = "assetId";
	}

	// 群组成员表
	/**
	 * comment on column TS_GROUP_USER.GU_UUID is '群成员信息表-主键id';
	 * 
	 * comment on column TS_GROUP_USER.GROUP_ID is '群id(唯一值)';
	 * 
	 * comment on column TS_GROUP_USER.USERTYPE is '群成员类型1:群主，2：群成员';
	 * 
	 * comment on column TS_GROUP_USER.DISPLAYNAME is '显示名称';
	 * 
	 * comment on column TS_GROUP_USER.USER_ACCOUNT is '用户账号';
	 * 
	 * comment on column TS_GROUP_USER.USER_STATUS is '用户状态0：待审核；1：可用。2：冻结';
	 * 
	 * comment on column TS_GROUP_USER.CREATE_DATE is '创建时间';
	 * 
	 * comment on column TS_GROUP_USER.CREATE_USER is '创建人账号';
	 * 
	 * comment on column TS_GROUP_USER.GU_REMARK is '备注信息';
	 * 
	 * comment on column TS_GROUP_USER.ISAUT is '是否已经认证 0：未认证。1： 已经认证';
	 * 
	 * comment on column TS_GROUP_USER.SPNAME is '名字首拼音';
	 * 
	 * comment on column TS_GROUP_USER.FNAME_FPY_NUM is '姓名拼音的前12个字母的Long排序值';
	 * 
	 * comment on column TS_GROUP_USER.QPNAME is '名称全拼';
	 * 
	 * comment on column TS_GROUP_USER.COMPANY is '公司名称';
	 * 
	 * comment on column TS_GROUP_USER.DEPARTMENT is '部门名称';
	 * 
	 * comment on column TS_GROUP_USER.JOBPROFESSION is '职位';
	 * 
	 * comment on column TS_GROUP_USER.ISJTUSER is '是否是集团用户0：否。1： 是';
	 **/
	public static final class TS_GROUP_USER implements BaseColumns {
		private TS_GROUP_USER() {

		}

		public static final String GU_UUID = "GU_UUID";
		public static final String GROUP_ID = "GROUP_ID";
		public static final String USERTYPE = "USERTYPE";
		public static final String DISPLAYNAME = "DISPLAYNAME";
		public static final String USER_ACCOUNT = "USER_ACCOUNT";
		public static final String USER_STATUS = "USER_STATUS";
		public static final String CREATE_DATE = "CREATE_DATE";
		public static final String CREATE_USER = "CREATE_USER";
		public static final String GU_REMARK = "GU_REMARK";
		public static final String ISAUT = "ISAUT";
		public static final String SPNAME = "SPNAME";
		public static final String FNAME_FPY_NUM = "FNAME_FPY_NUM";
		public static final String QPNAME = "QPNAME";
		public static final String COMPANY = "COMPANY";
		public static final String DEPARTMENT = "DEPARTMENT";
		public static final String JOBPROFESSION = "JOBPROFESSION";
		public static final String ISJTUSER = "ISJTUSER";
		public static final String ISTEMP = "ISTEMP";
		public static final String INSTALL = "INSTALL";

	}

	public static final class TS_DATA_VERSION implements BaseColumns {
		private TS_DATA_VERSION() {

		}

		public static final String GROUP_LIST_ID = "-888";// 群组列表的时间戳
		public static final String GROUP_LIST_AND_MEMBER = "-999";// 获取全部群组及群组成员的时间
		public static final String _ID = "_id";
		public static final String GROUP_ID = "groupid";
		public static final String TIMESTAMP = "timestamp";
		public static final String GROUP_TIME = "group_time";

	}

	public static final class CALL_LOG_INFO implements BaseColumns {
		private CALL_LOG_INFO() {

		}

		public static final String ID = "_id";
		public static final String NAME = "name";
		public static final String TEL = "tel";
		public static final String CALL_STATUS = "callStatus";
		public static final String CALL_TYPE = "call_type";
		public static final String TIME = "time";
		public static final String IS_UP = "isUp";
		public static final String INSTALL = "install";
		public static final String SOUNDURL = "soundurl";
		public static final String SOUND_TIME = "soundtime";
		public static final String IS_READ = "isRead";
		public static final String TABLE_NAME = "call_log_info";
		// update:2016年11月18日添加
		public static final String OUTSITE_PREFIX = "outsite_Prefix";// 外线字冠
		public static final String OTHERPLACE_PREFIX = "otherplace_prefix";// 异地字冠
		public static final String DURATON = "duration";// 时长

	}

	public static final class IMS_ACCOUNT_INFO implements BaseColumns {
		private IMS_ACCOUNT_INFO() {

		}

		public static final String ACCOUNT_ID = "account_id";
		public static final String IMS_ACCOUNT = "ims_account";
		public static final String IMS_PASSWORD = "ims_password";
		public static final String IMS_REALM = "ims_realm";
		public static final String IMS_HOST = "ims_host";
		public static final String IMS_PORT = "ims_port";
		public static final String IMS_IMPI = "ims_impi";
		public static final String TABLE_NAME = "ims_account_info";

	}

	public static final class APP_DOWNLOAD_INFO implements BaseColumns {
		private APP_DOWNLOAD_INFO() {

		}

		public static final String APP_ID = "_id";// id
		public static final String URL = "url";// 下载地址
		public static final String NAME = "app_name";// 应用名称
		public static final String FILE_SIZE = "file_size";// 文件大小
		public static final String FILE_PATH = "file_path";// 下载后存在本地的文件地址
		public static final String DOWNLOADED_SIZE = "downloaded_size";// 已经下载的大小
		public static final String PACKAGE = "app_package";// app包名
		public static final String DETAIL = "app_descri";// app描述
		public static final String VERISON_CODE = "app_version_code";// app版本号
		public static final String VERSION_NAME = "app_version_name";// app版本名
		public static final String STATUS = "download_status";// 下载状态
		public static final String ICON = "app_icon_path";// app图标
		public static final String REMARK = "remark";//
		public static final String TABLE_NAME = "app_download_info";//

	}

	public static final class RelationTable implements BaseColumns {
		private RelationTable() {

		}

		public static final String TABLE_NAME = "relation_table";
		public static final String ID = "_id";
		public static final String NAME = "name";
		public static final String TEL = "tel";

	}

	public static final class WidgetContactListTable implements BaseColumns {
		private WidgetContactListTable() {

		}

		public static final String TABLE_NAME = "widget_contact_list_table";
		public static final String ID = "_id";
		public static final String APPWIDGET_ID = "appWidget_id";
		public static final String NAME = "name";
		public static final String PHONE = "phone";
	}

	public static final class APP_CONTACTS implements BaseColumns {
		private APP_CONTACTS() {

		}

		public static final String TABLE_NAME = "app_contacts";
		public static final String ID = "_id";// id
		public static final String DISPLAY_NAME = "display_name";// 姓名
		public static final String EMAIL_ADDREDD = "email_address";// 电子邮件
		public static final String ALL_CHARACTER = "pinyin";// 拼音
		public static final String FIRST_CHARACTER = "first_pinyin";// 拼音首字母
		public static final String ALL_CHARACTER_T9 = "pinyin_T9";// 拼音
		public static final String FIRST_CHARACTER_T9 = "first_pinyin_T9";// 拼音首字母
		public static final String IS_COMMON_CONTACT = "is_common_contact"; // 是否为常用联系人
		public static final String PHOTO_ID = "photo_id";// 头像
	}

	public static final class APP_CONTACTS_DATA implements BaseColumns {
		private APP_CONTACTS_DATA() {

		}

		public static final String TABLE_NAME = "app_contacts_data";
		public static final String ID = "_id";// id
		public static final String CONTACTS_ID = "contact_id"; // 联系人id
		public static final String DATA = "data"; // 保存数据
		public static final String TYPE = "type"; // 类型
	}

	public static final class COMPANY_COMMON_CONTACT implements BaseColumns {
		private COMPANY_COMMON_CONTACT() {

		}

		public static final String TABLE_NAME = "company_common_contact";
		public static final String DISPLAY_NAME = "display_name";// 姓名
		public static final String PHONE = "phone";// 姓名
		public static final String UUID = "company_uuid";
				

	}
	// /**
	// * Upgrade tables. In this method, the sequence is:
	// * <b>
	// * <p>[1] Rename the specified table as a temporary table.
	// * <p>[2] Create a new table which name is the specified name.
	// * <p>[3] Insert data into the new created table, data from the temporary
	// table.
	// * <p>[4] Drop the temporary table.
	// * </b>
	// *
	// * @param db The database. 数据库
	// * @param tableName The table name. 表名
	// * @param columns The columns range, 旧表的字段;
	// */
	// protected void upgradeTables(SQLiteDatabase db, String tableName, String
	// columns)
	// {
	// try
	// {
	// db.beginTransaction();
	//
	// // 1, Rename table.
	// String tempTableName = tableName + "_temp";
	// String sql = "ALTER TABLE " + tableName +" RENAME TO " + tempTableName;
	// db.execSQL(sql);
	//
	// // 2, Create table.
	// onCreate(db);
	//
	// // 3, Load data
	// sql = "INSERT INTO " + tableName +
	// " (" + columns + ") " +
	// " SELECT " + columns + " FROM " + tempTableName;
	//
	// db.execSQL(sql);
	// sql="DROP TABLE IF EXISTS " + tempTableName;
	// // 4, Drop the temporary table.
	// db.execSQL(sql);
	//
	// db.setTransactionSuccessful();
	// }
	// catch (SQLException e)
	// {
	// e.printStackTrace();
	// }
	// catch (Exception e)
	// {
	// e.printStackTrace();
	// }
	// finally
	// {
	// db.endTransaction();
	// }
	// }
	//
	// /**
	// * 获取表的结构
	// * @param db
	// * @param tableName
	// * @return
	// */
	// public String getColumnNames(SQLiteDatabase db, String tableName){
	// StringBuilder sb=new StringBuilder();
	// Cursor c = null;
	//
	// try{
	// c = db.rawQuery("PRAGMA table_info(" + tableName + ")", null);
	// if (null != c){
	// int columnIndex = c.getColumnIndex("name");
	// if (-1 == columnIndex){
	// return null;
	// }
	//
	//
	// for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
	// String str = c.getString(columnIndex);
	// sb.append(str).append(",");
	// }
	// if(sb.length()>0) sb.deleteCharAt(sb.length()-1);
	//
	// }
	// }catch (Exception e){
	// e.printStackTrace();
	// }finally{
	// if(c!=null){
	// c.close();
	// }
	// }
	//
	// return sb.toString();
	// }

}
